import java.util.Date;
import java.util.Properties;

import cn.emay.common.cache.redis.RedisClient;
import cn.emay.common.cache.redis.RedisClusterClient;
import cn.emay.common.cache.redis.RedisSingleClient;
import cn.emay.util.DateUtil;

public class Test {

	private static RedisClient redisClient;

	public static void initRedis() {
		String type = "single";
		String timeout = "5000";
		String maxTotal = "16";
		String maxIdle = "8";
		String minIdle = "4";
		String maxWaitMillis = "2000";
		Properties properties = new Properties();
		properties.setProperty("timeout", timeout);
		properties.setProperty("maxIdle", maxIdle);
		properties.setProperty("maxTotal", maxTotal);
		properties.setProperty("minIdle", minIdle);
		properties.setProperty("maxWaitMillis", maxWaitMillis);
		if ("single".equalsIgnoreCase(type)) {
			String host = "127.0.0.1";
			String port = "6379";
			properties.setProperty("host", host);
			properties.setProperty("port", port);
			RedisSingleClient client1 = new RedisSingleClient();
			client1.setProperties(properties);
			client1.init();
			redisClient = client1;
		} else {
			String hosts = "127.0.0.1:8979,127.0.0.1:8971";
			String maxRedirections = "5";
			properties.setProperty("hosts", hosts);
			properties.setProperty("maxRedirections", maxRedirections);
			RedisClusterClient client1 = new RedisClusterClient();
			client1.setProperties(properties);
			client1.init();
			redisClient = client1;
		}
	}
	/***
	 * 向中心redis的上行队列写入数据
	 */
	public static void inRedisMo(){
		initRedis();
		long l = 18800000000l;
		for (int i = 0; i < 1; i++) {
			String mobile = l + i + "";
			RemoteSmsMo mo = new RemoteSmsMo();
			mo.setAppId("EUCP-EMY-0000-KCQOK");
			mo.setRowKey("2#######|682779##|" + DateUtil.toString(new Date(), "yyyyMMddHHmmss") + "|" + mobile + "|1#######");
			mo.setServiceCode("682779");
			mo.setMobileMoTime(DateUtil.toString(new Date(), "yyyy-MM-dd HH:mm:ss SSS"));
			mo.setRemoteAddress("100.100.10.85:20875");
			mo.setChannelId("1");
			mo.setEnterpriseId("2");
			mo.setChannelName("10086");
			mo.setContent("aa");
			mo.setMobile(mobile);
			mo.setExtendedCode(null);
			redisClient.lpush("CENTER_MO_QUEUE", -1, mo);
		}
	}
	
	/***
	 * 向中心redis的状态报告队列写入数据
	 */
	public static void inRedisReport(){
		initRedis();
		long l = 18800000000l;
		for (int i = 0; i < 1; i++) {
			String mobile = l + i + "";
			ReportDAO report = new ReportDAO();
			report.setAppId("EUCP-EMY-0000-KCQOK");
			report.setCenterReportPushTime("2017-01-20 15:29:24");
			report.setCenterReportResultReveiceTime(null);
			report.setClientGetterReportIp(null);
			report.setClientGetterReportTime(null);
			report.setCustomSmsId("111");
			report.setDesc("\\xe5\\x8f\\x91\\xe9\\x80\\x81\\xe6\\x88\\x90\\xe5\\x8a\\x9f");
			report.setExtendedCode(null);
			report.setMobile(mobile);
			report.setReceiveTime("2017-01-19 15:29:24");
			report.setRemoteReportReceiveTime("2017-01-19 15:29:24");
			report.setRemoteReportResultPushTime(null);
			report.setRomeAddress("100.100.10.85:20875");
			report.setRowKey("11######|475406##|" + DateUtil.toString(new Date(), "yyyyMMddHHmmss") + "|" + mobile + "|24######|100148480703732900");
			report.setServiceCode("475406");
			report.setSmsId("100148480703732900");
			report.setState("DELIVRD");
			report.setSubmitTime("2017-01-19 15:29:24");
			redisClient.lpush("REMOTE_SMS_REPORT_QUEUE_EUCP-EMY-0000-KCQOK", -1, report);
		}
	}
	

	public static void main(String[] args) {

		inRedisReport();
	}
}
